/*

*/


#include "time.h"


//取微秒时间截
static int get_time_us(lua_State* L){
    struct timeval tv;
    gettimeofday(&tv, NULL);
    long time = tv.tv_sec * 1000000 + tv.tv_usec;
    lua_pushnumber(L, time);
    return 1;
}

//取毫秒时间截
static int get_time_ms(lua_State* L){
    struct timeval tv;
    gettimeofday(&tv, NULL);
    long time = tv.tv_sec * 1000 + tv.tv_usec /1000;
    lua_pushinteger(L, time);
    return 1;
}

//取秒时间截
static int get_time_se(lua_State* L){
    struct timeval tv;
    gettimeofday(&tv, NULL);
    int time = tv.tv_sec;
    lua_pushinteger(L, time);
    return 1;
}


void time_reg(luaL_Reg lib[], int index){
    lib[index] = (luaL_Reg){"get_time_us", get_time_us};
    lib[index+1] = (luaL_Reg){"get_time_ms", get_time_ms};
    lib[index+2] = (luaL_Reg){"get_time_se", get_time_se};
}